package org.vaadin.nf4v.core.config;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Base configuration class.
 * All configurations has by conversion two types of "attributes":
 * 1. parameters - should be set with configuration DSL (human readable, holds some configuration semantic: e.g. name of menu category)
 * 2. attributes - used by framework internally or by extensions to register additional configurations (implementations specific staff)
 * (e.g. handlers overridden, annotations processing results etc.)
 */
public abstract class AbstractConfig implements Serializable {

    // used in dsl
    protected Map<String, String> params = new HashMap<String, String>();
    // used by extensions to store configurations
    protected Map<String, Object> attributes = new HashMap<String, Object>();

    /**
     * @return configuration parameters
     */
    public Map<String, String> getParams() {
        return params;
    }

    /**
     * Sets configuration parameter.
     *
     * @param name  parameter name
     * @param value parameter value
     */
    public void setParam(String name, String value) {
        params.put(name, value);
    }

    /**
     * @param name parameter name
     * @return configuration parameter
     */
    public String getParam(String name) {
        return params.get(name);
    }

    /**
     * @return configuration attributes
     */
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    /**
     * Sets configuration attribute
     *
     * @param name  attribute name
     * @param value attribute value
     */
    public void setAttribute(String name, Object value) {
        attributes.put(name, value);
    }

    /**
     * @param name attribute name
     * @return configuration attribute
     */
    @SuppressWarnings("unchecked")
    public <T> T getAttribute(String name) {
        return (T) attributes.get(name);
    }
}
